package cn.portx.report;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

import com.bstek.bdf3.security.orm.User;

import cn.portx.frame.PersonCenterPR;
import cn.portx.frame.entity.Company;
import cn.portx.view.ExportPR;

@Component("userReport")
public class UserReport {

	@Autowired
	private PersonCenterPR personCenterPR;

	@Autowired
	private ExportPR exportPR;

	public List<Map<String, Object>> loadData(String dsName, String datasetName, Map<String, Object> parameters) {

		List<Map<String, Object>> values = new ArrayList<Map<String, Object>>();

		User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();

		Company company = personCenterPR.getCompany();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("companyName", company.getFullName());
		map.put("loginUserName", user.getNickname());
		map.put("tel", company.getTel());
		values.add(map);

		return values;
	}

	public List<Map<String, Object>> loadBoxtype(String dsName, String datasetName, Map<String, Object> parameters) {
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		Map<String, Object> map = this.exportPR.loadBoxtype();
		for (String key : map.keySet()) {
			Map<String, Object> m = new HashMap<String, Object>();
			m.put("key", key);
			m.put("value", map.get(key));
			list.add(m);
		}
		return list;
	}

}
